# 1. 百度智能云 - 人脸检测定位
import requests

def baidu_keyword(title,content):
    """人脸检测定位"""
    url = "https://aip.baidubce.com/rest/2.0/face/v3/DetectLabel"
    
params = "{\image\":\"027d8308a2ec665acb1dbf63e513bcb9\",\"image_typr\":\"face_token\",\"face_field\":\"faceshape,facetype\"}"
access_token = '24.6c5e1ff107f0e8bcef8c46d3424a0e78.2592000.1485516651.282335-8574074'
requests_url = request_url + "?access_token=" + access_token
headers = {'content-type':'application/json'}
response = requests.post(request_url,data=params,headers=hearders)
if response:
     print(response.json())


# 输出：
{

    "face_num":1,
    "face_list":[
        {
            "face_token":
            "a85d6jhbcujewk62626526",
            "location":{
                     "left":318.38,
                     "top":323.56,
                     "width":447,
                     "height":481,
                     "rotation":-1                                                                      
                                                                                         
            }
            "face_probability":1,
            "angle":
        }
    ]



# 2. 美图AI开放平台————皮肤分析
import requests
import base64
import json

def algorhtmReq():
    image = open('./timg.jpeg', 'rb')
    image_read = image.read()
    image_64_encode = base64.encodestring(image_read).decode('utf-8')
    ss = json.dumps(
    {
        "parameter": {
            "rsp_media_type": "jpg",
        },
        "extra": {},
        "media_info_list": [{
            "media_data": image_64_encode,
            "media_profiles": {
                "media_data_type":"jpg"
            },
            "media_extra": {
            }
        }]

    }
    )

    AIBeauty_url = "https://openapi.mtlab.meitu.com/v3/makeup?api_key=xxx&api_secret=xxx"
    print(ss)
    response = requests.post(AIBeauty_url, data=ss)
    ss2 = json.dumps(response.json())
    print(ss2)
    print(response.status_code)

if __name__ == "__main__":
    algorhtmReq()


# 输出：
{
"parameter": {
"nFront": 1
},
"extra": {
},
"media_info_list": [
{
"media_data": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy...",
"media_profiles": {
"media_data_type": "jpg"
}
}
]
}

# 3. 美图AI开放平台————五官分割
import requests
import base64
import json

def algorhtmReq():
    image = open('./timg.jpeg', 'rb')
    image_read = image.read()
    image_64_encode = base64.encodestring(image_read).decode('utf-8')
    ss = json.dumps(
{
    "parameter": {
        "rsp_media_type": "url",
        "version":"1.0.0",
        "nMaskType":"0"
    },
    "extra": {},
    "media_info_list": [{
        "media_data": "...",
        "media_profiles": {
            "media_data_type": "jpg"
        }
    }]

}
)

    AIBeauty_url = "https://openapi.mtlab.meitu.com/v1/PhotoSegment"
    print(ss)
    response = requests.post(AIBeauty_url, data=ss)
    ss2 = json.dumps(response.json())
    print(ss2)
    print(response.status_code)

if __name__ == "__main__":
    algorhtmReq()

# 输出：
{
    "parameter": {
            "rsp_media_type":"jpg"
    }, 
    "media_info_list": [{
        "media_data": "...",
        "media_profiles": {
            "media_data_type": "jpg"
        }
    }]
}